/*
"betting game":the rule is:
computer shuffles cards"Jack Queen King"
player guess the position of Queen
if win,take 3*bet
if loose,loose the bet amount
player have $100 begin
*/

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

int cash=100;

int main(){

    int bet;
    srand(time(NULL));   //设置伪随机数种子

    void Play(int bet){
        // char C[3]={'J','Q','K'};
        char* C=(char*)malloc(3*sizeof(char));
        C[0]='J';C[1]='Q';C[2]='K';
        printf("Shuffling--------\n");
        for(int i=0;i<5;i++){ //伪随机数打乱
            int x=rand()%3;
            int y=rand()%3;
            int temp=C[x];
            C[x]=C[y];
            C[y]=temp;
        }
        int PlayerGuess;
        printf("What's the position of Queen-1,2or3? ");
        scanf(" %d",&PlayerGuess);
        if((PlayerGuess-1)=='Q'){
            cash+=3*bet;
            printf("You Win!  Resulte=%c %c %c Cash=%d\n",C[0],C[1],C[2],cash);
        }
        else{
            cash-=bet;
            printf("You Lose! Resulte=%c %c %c Cash=%d\n",C[0],C[1],C[2],cash);
        }

    }

    while(cash>0){
        printf("what your bet? $ ");
        scanf(" %d",&bet);
        if(bet==0||bet>cash)break;
        Play(bet);
        printf("-----------------------------------\n");

    }









}